package com.xiaor.rssmodel.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xiaor.rssmodel.model.common.Common;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * 历史人物
 */
@Entity
@Table(name = "figure")
@Data   //生成Getter和Setter
@NoArgsConstructor  //生成无参构造函数
@AllArgsConstructor //生成有参构造函数
public class Figure extends Common {
    @Column(columnDefinition = "varchar(50) comment '人物名称'", unique = true)
    private String name;
    @Column(columnDefinition = "varchar(50) comment '人物名称拼音'")
    private String pinyin;
    @Column(columnDefinition = "varchar(255) comment '人物简介'", unique = true)
    private String introduction;
    @Column(columnDefinition = "datetime comment '出生日期'", unique = true)
    @JsonFormat(
            pattern = "yyyy年MM月dd日",
            timezone = "GMT+8"
    )
    private Date birthday;
    @Column(columnDefinition = "datetime comment '过世时间'", unique = true)
    @JsonFormat(
            pattern = "yyyy年MM月dd日",
            timezone = "GMT+8"
    )
    private Date death_time;
    @ManyToMany
    @JoinTable(name = "event_figure",
            joinColumns = {@JoinColumn(name = "fid")},
            inverseJoinColumns = {@JoinColumn(name = "eid")}
    )
    private List<Event> eventList;
    @ManyToMany
    @JoinTable(name = "area_figure",
            joinColumns = {@JoinColumn(name = "fid")},
            inverseJoinColumns = {@JoinColumn(name = "aid")}
    )
    private List<Area> areaList;
    @OneToMany
    @JoinTable(name = "figure_fimage",
            joinColumns = {@JoinColumn(name = "fid")},
            inverseJoinColumns = {@JoinColumn(name = "mid")}
    )
    private List<FImage> fImageList;

    @Override
    public String toString() {
        return "Figure{" +
                "name='" + name + '\'' +
                ", introduction='" + introduction + '\'' +
                ", birthday=" + birthday +
                ", death_time=" + death_time +
                '}';
    }
}
